// @ts-ignore
/* eslint-disable */
import { request } from "umi";

// 获取当前的用户
export async function currentUser(options?: { [key: string]: any }) {
  return new Promise<API.CurrentUser>((resolve, reject) => {
    let user = JSON.parse(localStorage.getItem('userinfo') as string);
    resolve(user);
  })
}
//获取用户管理信息
export const getUser =async (params:any) => request('/api/user',{
  params
})
export const searchUserData = async (obj:any) =>{
  let {account , email,status,role ,page} = obj
  //let {pages,pageSize} =page
  if(page&& role){
    return request('/api/user',{
      params:{
        role,
      page:page.page,
      pageSize:page.pageSize
      }
    })
  }
  
}
// 更新用户信息
export const updateUserApi = async (data:any)=>request('/api/user/update',{
  method:'POST',
  data,
})
// 获取文章数据
export const getAledataApi = async (params: any) => request(`/api/article`, {
  method: 'GET',
  params,
});
// 文章发布
export const addAleApi = async (data: any) => request('/api/article', {
  method: 'POST',
  data,
})
// 获取分类接口
export const getCAteApi = async () => request('/api/category', { method: 'GET' });
// 添加分类
export const addCateApi = async (data: any) => request('/api/category', { method: 'POST', data });
// 更新分类
export const putCateApi = async (id: string, data: any) => request('/api/category/' + id, { method: 'PATCH', data });
// 删除分类
export const delCateApi = async (id: string) => request('/api/category/' + id, { method: 'DELETE' });
// 获取标签接口
export const getTagApi = async () => request('/api/tag', { method: 'GET' });
// 添加标签
export const addTagApi = async (data: any) => request('/api/tag', { method: 'POST', data });
// 更新标签
export const putTagApi = async (id: string, data: any) => request('/api/tag/' + id, { method: 'PATCH', data });
// 删除标签
export const delTagApi = async (id: string) => request('/api/tag/' + id, { method: 'DELETE' });
// 最新文章数据
export const getAledata = async () => request(`/api/article`, {
  method: 'GET',
})
// 文章数据筛选
export const setNewdataApi = async (params: any) => {
  let { pages, status, title, category } = params;
  let { page, pageSize } = pages;
  if (params.pages && params.title && params.status && params.category) {
    return request('/api/article', {
      method: 'GET',
      params: {
        page,
        pageSize,
        title,
        status,
        category
      }
    })
  }
  else if (params.pages && params.title && params.status) {
    return request('/api/article', {
      method: 'GET',
      params: {
        page,
        pageSize,
        title,
        status,
      }
    })
  }
  else if (params.pages && params.title && params.category) {
    return request('/api/article', {
      method: 'GET',
      params: {
        page,
        pageSize,
        title,
        category
      }
    })
  }
  else if (params.pages && params.title) {
    return request('/api/article', {
      method: 'GET',
      params: {
        page,
        pageSize,
        title,
      }
    })
  }
  else if (params.pages && params.status) {
    return request('/api/article', {
      method: 'GET',
      params: {
        page,
        pageSize,
        status
      }
    })
  }
  else if (params.pages && params.category) {
    return request('/api/article', {
      method: 'GET',
      params: {
        page,
        pageSize,
        category
      }
    })
  }
}
// 数据删除
export const delAledataApi = async (id:string)=>request('/api/article/'+id,{method:'DELETE'});
// 全选操作
export const allApi = async(id:string,data:any)=>request('/api/article/'+id,{
  method:'PATCH',
  data,
})
// 推荐-撤销 
export const allNowApi = async(id:string,data:any)=>request('/api/article/'+id,{
  method:'PATCH',
  data,
});

// 所有所有页面
export const getpagedataApi = async (params: any) => request(`/api/page`, {
  method: 'GET',
  params,
});
// 页面数据筛选
export const setpagedataApi = async (params: any) => {
  let { pages, status, name, path } = params;
  let { page, pageSize } = pages;
  if (params.pages && params.name && params.status && params.path) {
    return request('/api/page', {
      method: 'GET',
      params: {
        page,
        pageSize,
        name,
        status,
        path
      }
    })
  }
  else if (params.pages && params.name && params.status) {
    return request('/api/page', {
      method: 'GET',
      params: {
        page,
        pageSize,
        name,
        status,
      }
    })
  }
  else if (params.pages && params.name && params.path) {
    return request('/api/page', {
      method: 'GET',
      params: {
        page,
        pageSize,
        name,
        path
      }
    })
  }
  else if (params.pages && params.name) {
    return request('/api/page', {
      method: 'GET',
      params: {
        page,
        pageSize,
        name,
      }
    })
  }
  else if (params.pages && params.status) {
    return request('/api/page', {
      method: 'GET',
      params: {
        page,
        pageSize,
        status
      }
    })
  }
  else if (params.pages && params.path) {
    return request('/api/page', {
      method: 'GET',
      params: {
        page,
        pageSize,
        path
      }
    })
  }
}
// 页面数据全选操作
export const allpathApi = async(id:string,data:any)=>request('/api/page/'+id,{
  method:'PATCH',
  data,
});
// 页面管理数据删除
export const delpathdataApi = async (id:string)=>request('/api/page/'+id,{method:'DELETE'});


// 页面管理发布-下线 
export const allPageApi = async(id:string,data:any)=>request('/api/page/'+id,{
  method:'PATCH',
  data,
});
















/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<API.LoginResult>('/api/auth/login', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}
//  注册
export const register = (data: any) => request('/api/user/register', {
  method: 'POST',
  data,
})

